package com.itheima.demo;

import com.itheima.domain.Role;
import com.itheima.mapper.RoleMapper;
import com.itheima.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

//测试类
public class RoleDemo {
    @Test
    public void testFindAll(){
        SqlSession session = MapperUtils.getSqlSession();

        RoleMapper mapper = session.getMapper(RoleMapper.class);
        List<Role> list = mapper.findAll();
        for (Role role : list) {
            System.out.println(role);
        }
        MapperUtils.close(session);
    }

    @Test
    public void testFindById(){
        SqlSession session = MapperUtils.getSqlSession();

        RoleMapper mapper = session.getMapper(RoleMapper.class);
        Role role = mapper.findById(1);
        System.out.println(role);
        MapperUtils.close(session);
    }

    @Test
    public void findById2(){
        SqlSession session = MapperUtils.getSqlSession();

        RoleMapper mapper = session.getMapper(RoleMapper.class);
        List<Role> byId2 = mapper.findById2(0);
        for (Role role : byId2) {
            System.out.println(role);
        }
        MapperUtils.close(session);
    }


    @Test
    public void findById3(){
        SqlSession session = MapperUtils.getSqlSession();
        RoleMapper mapper = session.getMapper(RoleMapper.class);
        Integer[] ids = {1,2,3,4,5,7};
        List<Role> list = mapper.findById3(ids);
        for (Role role : list) {
            System.out.println(role);
        }
        MapperUtils.close(session);
    }

}
